<template>
  <div class="dataCenter">
    <div class="dataNav" v-loading="findFinanceReportSizeVoLoading">
      <div class="lable">总计信息《财务+三资》</div>
      <div class="dataCount">
        <div class="countItem">
          <img src="@/assets/image/count1.png" alt="" />
          <div class="countNum">
            <span>{{ findFinanceReport.villageReportNumber }}</span>
            <span>村-报表</span>
          </div>
        </div>
        <div class="countItem">
          <img src="@/assets/image/count2.png" alt="" />
          <div class="countNum">
            <span>{{ findFinanceReport.communityReportNumber }}</span>
            <span>社区-报表</span>
          </div>
        </div>
        <div class="countItem">
          <img src="@/assets/image/count6.png" alt="" />
          <div class="countNum">
            <span>{{ findFinanceReport.committeeReportNumber }}</span>
            <span>居委-报表</span>
          </div>
        </div>
        <div class="countItem">
          <img src="@/assets/image/count3.png" alt="" />
          <div class="countNum">
            <span>{{ findFinanceReport.auditNumber }}</span>
            <span>审核中-报表</span>
          </div>
        </div>
        <div class="countItem">
          <img src="@/assets/image/count4.png" alt="" />
          <div class="countNum">
            <span>{{ findFinanceReport.publicNumber }}</span>
            <span>已公开-报表</span>
          </div>
        </div>
      </div>
    </div>
    <!-- 数据审批信息 -->
    <div class="content">
      <div class="tabCont" v-loading="findDataBlackListLoading">
        <div class="tabNav">
          <div class="flex1 spanTxt">
            《财务公开》数据看板
          </div>
          <div class="flex2 tabMonth">
            <div class="pickerTime">
              <div class="time">
                <el-date-picker ref="saveDateInput" v-model="optionMonth" value-format="YYYY-MM" type="month"
                  :clearable="false" :disabled-date="disabledDate" @change="changeMonthTime" placeholder="选择月份">
                </el-date-picker>
              </div>
              <div class="datTime" @click="openDataPicker">
                <p>{{ optionMonth }}</p>
                <down theme="filled" size="22" fill="#333" />
              </div>
            </div>
          </div>
          <div class="flex3">
            <div class="selectTab">
              <el-select @change="changeArea" v-model="value" class="m-2" placeholder="区域选择">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </div>
          </div>
        </div>
        <div class="stateAll">
          <div class="stateOne"><i class="bgCol6"></i>审核中({{ dataBloackPojo.underAuditNumber }})</div>
          <div class="stateOne"><i class="bgCol7"></i>已通过({{ dataBloackPojo.auditPassedNumber }})</div>
          <div class="stateOne"><i class="bgCol8"></i>已公开({{ dataBloackPojo.publicNumber }})</div>
          <div class="stateOne"><i class="bgCol9"></i>未上报({{ dataBloackPojo.waitSubmitNumber }})</div>
        </div>
        <div class="tabBlockBox scrollbar">
          <div class="tabBlockList">
            <div :key="index" v-for="(item, index) in dataBloackPojo.areaReportAuditStates"
              :style="{ background: item.auditStateColor }" class="blockItem">
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
      <div class="listCont">
        <div class="label">操作记录</div>
        <div class="headerTit">
          <div class="span1">用户</div>
          <div class="span2">时间</div>
          <div class="span3">操作</div>
        </div>
        <div class="recordList scrollbar" v-loading="findFinanceLogListLoading">
          <div class="recordLi" v-for="(item, index) in financeLogs" :key="index">
            <div class="span1">{{ item.username }}</div>
            <div class="span2">{{ item.createTime }}</div>
            <div class="span3 line-1">
              <NormalTextTooltipol :text="item.logContent" />
            </div>
          </div>
          <div class="noList" v-if="financeLogs == null || financeLogs.length == 0">
            <img style="width: 330px; height: 210px" src="@/assets/image/count5.png" />
            <div class="textTip">暂无操作记录</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { ElMessage, ElMessageBox } from 'element-plus'
import NormalTextTooltipol from '@/components/NormalTextTooltipol'

import { mapState } from 'vuex'
export default {
  name: "financeDataCenter",
  components: {
    NormalTextTooltipol,
  },
  computed: {
    ...mapState(['isCollapse']),
  },
  watch: {
    isCollapse(newVal) {
    },
  },
  data() {
    return {
      ...mapState,
      findFinanceReport: {},
      findFinanceReportSizeVoLoading: false,
      value: '',
      optionMonth: '',
      disabledDate: (time) => {
        return time.getTime() > Date.now()
      },
      userInfo: {},
      options: [],
      findDataBlackListLoading: false,
      dataBloackPojo: {},
      financeLogs: [],
      findFinanceLogListLoading: false,
    }
  },
  mounted() {
    this.optionMonth = this.formatDate(this.getlastMonth(), 'yyyy-MM')
    this.userInfo = JSON.parse(localStorage.getItem('dtUsersVo'))
    let u = JSON.parse(localStorage.getItem('dtUsersVo'))
    this.options = [
      {
        value: 3,
        label: '村',
      },
      {
        value: 16,
        label: '社区',
      },
      {
        value: 4,
        label: '居委',
      },
    ]
    this.value = this.options[0].value
    // if (u.userMaxRole == 1 || u.userMaxRole == 3 || u.userMaxRole == 5) {
    //   this.options = [
    //     {
    //       value: 3,
    //       label: '村',
    //     },
    //   ]
    //   this.value = 3
    // } else if (u.userMaxRole == 2 || u.userMaxRole == 4 || u.userMaxRole == 6) {
    //   this.options = [
    //     {
    //       value: 16,
    //       label: '社区',
    //     },
    //   ]
    //   this.value = 16
    // } else if (u.userMaxRole == 7 || u.userMaxRole == 8) {
    //   this.options = [
    //     {
    //       value: 3,
    //       label: '村',
    //     },
    //     {
    //       value: 16,
    //       label: '社区',
    //     },
    //     {
    //       value: 16,
    //       label: '居委',
    //     },
    //   ]
    //   this.value = 3
    // }
    this.findFinanceReportSizeVo()
    this.findDataBlackList()
    this.findFinanceLogList()
  },
  methods: {
    // 当前时间的上一个月
    getlastMonth() {
      let now = new Date()
      // 当前月的日期
      let nowDate = now.getDate()
      let lastMonth = new Date(now.getTime())
      // 设置上一个月（这里不需要减1）
      lastMonth.setMonth(lastMonth.getMonth())
      // 设置为0，默认为当前月的最后一天
      lastMonth.setDate(0)
      // 上一个月的天数
      let daysOflastMonth = lastMonth.getDate()
      // 设置上一个月的日期，如果当前月的日期大于上个月的总天数，则为最后一天
      lastMonth.setDate(nowDate > daysOflastMonth ? daysOflastMonth : nowDate)
      return lastMonth
    },


    // 财务中心总计信息
    findFinanceReportSizeVo() {
      this.findFinanceReportSizeVoLoading = true
      this.$http.post('/axh/dataCenter/statisticsReportTotalNumber').then((res) => {
        if (res && res.result) {
          this.findFinanceReportSizeVoLoading = false
          this.findFinanceReport = res.result
        }
      })
    },

    // 数据看板
    findDataBlackList() {
      this.findDataBlackListLoading = true
      this.$http.post('/axh/dataCenter/selectAreaReportAuditInfoList', {
        areaType: this.value,
        month: this.optionMonth,
      }).then((res) => {
        if (res && res.result) {
          this.findDataBlackListLoading = false
          this.dataBloackPojo = res.result
        }
      })
    },

    // 操作记录
    findFinanceLogList() {
      this.findFinanceLogListLoading = true
      this.$http.post('/axh/dataCenter/selectUserOperationReportLogList', {
        page: 1,
        limit: 50
      }).then((res) => {
        if (res && res.result) {
          this.findFinanceLogListLoading = false
          this.financeLogs = res.result
        }
      })
    },

    // 切换村社区（数据看板）
    changeArea(e) {
      this.findDataBlackList()
    },

    // 切换时间
    changeMonthTime(e) {
      this.optionMonth = e
      this.findDataBlackList()
    },

    // 打开data-picker时间框
    openDataPicker() {
      this.$refs.saveDateInput.focus()
    },
  },
}
</script>
<style lang="scss" scoped>
.dataCenter {
  padding: 20px;
}

.dataNav {
  background: $bgColorFFFFFF;
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 20px;

  .lable {
    font-weight: bold;
    font-size: 20px;
    margin-bottom: 6px;
  }

  .dataCount {
    display: flex;

    .countItem {
      flex: 1;
      height: 88px;
      background: #f6f6f6;
      display: flex;
      border-radius: 4px;
      justify-content: space-between;
      align-items: center;
      margin-right: 32px;
      padding-right: 16px;
      padding-left: 5px;

      &:nth-last-child(1) {
        margin-right: 0;
      }

      img {
        width: 80px;
        height: 80px;
      }

      .countNum {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;

        span {
          text-align: right;

          &:nth-child(1) {
            font-weight: bold;
            font-size: 32px;
            color: $color35353F;
          }

          &:nth-child(2) {
            font-weight: 400;
            font-size: 16px;
            color: $color9E9E9E;
          }
        }
      }
    }
  }
}

.content {
  display: flex;
  margin-bottom: 20px;

  .tabCont {
    flex: 2;
    width: 730px;
    height: 714px;
    background: #ffffff;
    border-radius: 4px;
    margin-right: 20px;
    padding: 16px 6px 16px 16px;

    .tabNav {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 18px;
      padding-right: 10px;

      .spanTxt {
        font-size: 20px;
        color: $color35353F;
        font-weight: bold;
        display: flex;
        align-items: center;

        .noticeBtns {
          font-size: 16px;
          min-width: 80px;
          padding: 0 16px;
          text-align: center;
          height: 38px;
          line-height: 38px;
          color: #fff;
          background-color: rgb(44, 131, 228);
          margin-left: 12px;
          cursor: pointer;
          border-radius: 4px;
          transition: all 0.2s ease-out 0s;

          &:hover {
            background-color: rgba(44, 131, 228, 0.8);
          }
        }
      }

      .tabMonth {
        display: flex;
        align-items: center;
        color: $color35353F;
        font-size: 20px;

        .pickerTime {
          position: relative;
          width: 100px;
          cursor: pointer;

          .time {
            cursor: pointer;
            opacity: 0;
            position: absolute;
            top: -20px;
            left: 0;
            width: 100%;
          }

          .datTime {
            position: absolute;
            top: -20px;
            left: 0;
            font-size: 18px;
            font-weight: 400;
            display: flex;
            align-items: center;
            height: 38px;

            p {
              margin-right: 2px;
            }
          }
        }
      }

      .flex1 {
        flex: 1;
      }

      .flex2 {
        flex: 1;
        display: flex;
        justify-content: center;
      }

      .flex3 {
        flex: 1;
        display: flex;
        justify-content: flex-end;

        .selectTab {
          width: 100px;
        }
      }
    }

    .stateAll {
      font-size: 16px;
      display: flex;
      justify-content: space-between;
      margin-bottom: 16px;
      padding: 0 26px 0 16px;

      .stateOne {
        display: flex;
        align-items: center;

        i {
          display: inline-block;
          margin-right: 8px;
          width: 24px;
          height: 24px;
        }
      }
    }

    .tabBlockBox {
      height: 595px;
      overflow-y: auto;
      overflow-x: hidden;
      padding-right: 2px;

      .tabBlockList {
        display: flex;
        flex-wrap: wrap;

        .blockItem {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 98px;
          height: 98px;
          margin-right: 2px;
          margin-bottom: 2px;
          cursor: pointer;
          transition: all 0.2s ease 0s;
          background: #F9E2C0;
          &:hover {
            transform: scale(0.88);
          }
        }
      }
    }
  }

  .listCont {
    background: #ffffff;
    flex: 1;
    width: 0;
    height: 714px;
    padding: 16px;

    .label {
      font-size: 20px;
      font-weight: 600;
      margin-bottom: 24px;
    }

    .headerTit {
      width: calc(100% - 6px);
      font-size: 16px;
      display: flex;
    }

    .recordList {
      overflow-x: hidden;
      overflow-y: auto;
      height: 600px;

      .recordLi {
        display: flex;
        width: calc(100% - 6px);
        padding: 8px 0;
        color: $color999999;
      }
    }

    .span1 {
      width: 36%;
      padding-right: 3%;
    }

    .span2 {
      width: 28%;
      padding-right: 3%;
    }

    .span3 {
      width: 38%;
    }
  }
}

.chartCont {
  background: $bgColorFFFFFF;
  border-radius: 4px;
  height: 468px;
  padding: 16px;
  overflow: hidden;

  .lable {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 18px;
  }

  .chartMsg {
    position: relative;

    .msg1 {
      position: absolute;
      left: 0;
      top: 0;
      font-size: 14px;
    }

    .chartSelect {
      position: absolute;
      z-index: 9;
      right: 0;
      top: 0;
      width: 100px;
    }
  }
}
</style>
